package com.shaw.server;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

import org.hibernate.ejb.Ejb3Configuration;

import com.shaw.client.UserEntity;
import com.shaw.client.UserService;


import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class UserServiceImpl extends RemoteServiceServlet implements UserService {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static EntityManagerFactory emf;
	static{
		Ejb3Configuration ejb3Configuration=new Ejb3Configuration();
		ejb3Configuration.addAnnotatedClass(UserEntity.class);
		emf=ejb3Configuration.buildEntityManagerFactory();
		
		
	}
	
	@Override
	public UserEntity query(String names) {
		// TODO Auto-generated method stub
		EntityManager eManager=emf.createEntityManager();
		UserEntity uEntity=eManager.find(UserEntity.class, names);
	
		return uEntity;

	}

	public Boolean isSaved(UserEntity user) {
		// TODO Auto-generated method stub
		EntityManager eManager=emf.createEntityManager();
		eManager.getTransaction().begin();
		eManager.persist(user);
		eManager.getTransaction().commit();
	

		return true;
	}

	
}
